<?php
if ($with == 'html_css') 		// fully custom css
{
	echo $bricabox->custom_css;
}
elseif ($with == 'colors') 		// custom color scheme
{
	// load the css template
	$_css 		= @file_get_contents(BASEPATH.'../assets/themes/custom_colors.css');
	$parsed_css = $_css;
	
	// parse out vars; find all fields prefixed with "color_" and do some magic
	$color_fields = array();
	$query 		  = $this->db->query('show fields from bricaboxes');
	foreach ($query->result() as $row)
		if (strpos($row->Field, 'color_') !== false)
			$color_fields[] = $row->Field;
	
	foreach ($color_fields as $field)
	{
		// parse the tag for the default color in case none is set
		$tag = "\{$field\:([a-f0-9]+)\}";
		if (preg_match_all("/$tag/", $parsed_css, $matches))
			if (count($matches[1]))
			{
				// using preg_match_all() we can handle multiple instances of the same tag with different defaults, e.g.:
				// color: #{color_for_links:111};
				// border-bottom: 1px solid #{color_for_links:ddd};
				foreach ($matches[1] as $mtch)
				{
					$default_color = $mtch;
					if ($bricabox->$field)
						$proper_color = $bricabox->$field;
					else
						$proper_color = $default_color;
					
					$parsed_css = str_replace('{'.$field.':'.$default_color.'}', $proper_color, $parsed_css);
				}
			}
	}
	
	// render
	echo $parsed_css;
}
else 							// custom or default theme
{
	require_once $theme_dir.'theme.css';
}
?>